{% extends 'myadmin/index.html' %}
{% block 'body' %}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">分类列表</div>


                </div>
                <div class="widget-body  am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button type="button" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-secondary"><span class="am-icon-save"></span> 保存</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-warning"><span class="am-icon-archive"></span> 审核</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-danger"><span class="am-icon-trash-o"></span> 删除</button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <form>
                        <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                            <div class="am-form-group tpl-table-list-select">
                                <select name="class" data-am-selected="{btnSize: 'sm'}" style="display: none;">
                                  <option value="username" {% if request.GET.class == 'username' %} selected {% endif %}>会员名</option>
                                  <option value="phone" {% if request.GET.class == 'phone' %} selected {% endif %}>手机号</option>
                                  <option value="sex" {% if request.GET.class == 'sex' %} selected {% endif %}>性别</option>
                                </select>
                            </div>
                        </div>
                        <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                            <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                <input name="keywords" type="text" value="{{ request.GET.keywords }}" class="am-form-field ">
                                <span class="am-input-group-btn">
                                    <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" ></button>
                                </span>
                            </div>
                        </div>
                    </form>

                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                            <thead>
                                <tr>
                               
                                    <th>分类ID</th>
                                    <th>分类名</th>
                                    <th>所属分类</th>
                                    <th>path路径</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>

                                {% for v in types %}
                                <tr class="gradeX">
                                    
                                    <td class="am-text-middle tid">{{ v.id }}</td>
                                    <td class="am-text-middle typeedit">{{ v.name }}</td>
                                    <td class="am-text-middle">{{ v.pname }}</td>
                                    <td class="am-text-middle">{{ v.path }}</td>
                                    
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            
                                            <a href="{% url 'myadmin_typedel' v.id %}" class="tpl-table-black-operation-del">
                                                <i class="am-icon-trash"></i> 删除
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                {% endfor %}

       
                                <!-- more data -->
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">

                     
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
{% block 'js' %}

<script type="text/javascript">
    var ytext = ''
    // 获取typeedit 绑定双击事件
    $('.typeedit').dblclick(function(){
        // 获取当前的文件,创建一个输入框,value为原来的文本
        ytext = $(this).text()
        $(this).html('<input type="text" style="color:blue" value="'+ytext+'">')
        $(this).find('input').select()
    })
    $('.typeedit').find('input').live('blur',function(){
         // 绑定丧失焦点事件
         // 判断是否更新了name
        var xtext = $(this).val()
        if (ytext == xtext) {
            $(this).parent().html(ytext)
        }else{
            // 获取当前分类id
            tid = $(this).parents('tr').find('.tid').text()
            inp = $(this)
            // 发送ajax修改name
            $.get('{% url "myadmin_typeupdate" %}',{"id":tid,"name":xtext},function(data){
                // 判断是否修改成功
                if(data == 0){
                    inp.parent().html(xtext)
                }else{
                    inp.parent().html(ytext)

                }
            })
        }
    })



</script>


{% endblock %}